/**
 * HomeActivity.java
 */
package com.krui.iweibo.ui;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import weibo4android.Status;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.krui.iweibo.R;
import com.krui.iweibo.adapter.WeiboAdapter;
import com.krui.iweibo.model.Task;
import com.krui.iweibo.service.MainService;
import com.krui.iweibo.utils.SharedPreferenceUtil;

/**
 * HomeActivity.java
 * 
 * @author krui 2012-6-28 上午03:49:17
 * 
 */
public class HomeActivity extends BaseActivity  implements IweiboActivity{
	private static final String TAG = "HomeActivity";

	// 加载View
	private View progresView;

	private View titleView;

	private ListView weiboListView;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.home);
		init();

	}

	/**
	 * 添加获取微博信息任务
	 */
	private void newTask() {
		
		Map<String , Object> taskParams = new HashMap<String, Object>(1);
		taskParams.put("loginUser", currentUser);
		Task task = new Task(Task.WEIBO_FRIEDNS_TIMELINE, taskParams);

		MainService.newTask(task);

		MainService.addActivity(this);
	}

	public void init() {

		weiboListView = (ListView) this.findViewById(R.id.lv_weibos);
		progresView = this.findViewById(R.id.layout_progress);

		titleView = this.findViewById(R.id.layout_title_view_home);
		currentUser = SharedPreferenceUtil.getLoginUser(this);
		currentUser = dbAccess.getAllUsers().get(0);
		((TextView) titleView.findViewById(R.id.title_tv)).setText(currentUser.getUserName());

		newTask();

	}

	
	public void refresh(Object... params) {
		
		progresView.setVisibility(View.GONE);

		@SuppressWarnings("unchecked")
		List<Status> status = (List<Status>) params[0];

		WeiboAdapter adapter = new WeiboAdapter(this, status);
		weiboListView.setAdapter(adapter);

		Log.i(TAG, "ok--------");
	}

}
